<template>
  <!-- 首检操作（线材/组件预制） -->
  <p-card :bordered="false" :class="'cust-erp-sub-tab'">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24"></p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <p-button v-if="mainId" @click="handleAdd" type="primary" icon="plus">新增</p-button>

      <p-dropdown v-if="selectedRowKeys.length > 0">
        <p-menu slot="overlay">
          <p-menu-item key="1" @click="batchDel">
            <p-icon type="delete" />删除
          </p-menu-item>
        </p-menu>
        <p-button style="margin-left: 8px">
          批量操作
          <p-icon type="down" />
        </p-button>
      </p-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>


      <p-page-header
              style="border: 1px solid rgb(235, 237, 240)"
              title="首检操作（线材/组件预制）"
      >
        <template slot="extra">
          <p-button  type="primary" @click="saveData">保存</p-button>
          <p-popconfirm
                  title="确定要提交吗？"
                  ok-text="确定"
                  cancel-text="取消"
                  @confirm="submit_button"
                  @cancel="cancel"
          >
            <p-button type="primary">提交</p-button>
          </p-popconfirm>

          <p-button @click="backToIndex">取消</p-button>
        </template>
      </p-page-header>

      <h4 class="title">基础信息</h4>

      <p-form :form="form">
        <p-row>
          <p-col :span="8">
            <p-form-item label="送检单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['inspectBillno']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="生产工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['productionBillno']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="工序工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['processBillno']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['mcode']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['mname']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="二级工序" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['processTwo']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['linename']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="设备编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['deviceCode']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="检验次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['inspectTimes']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="检验人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['inspectBy']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <p-col :span="8">
            <p-form-item label="送检时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['sendInspectTime']" readOnly></p-input>
            </p-form-item>
          </p-col>

          <!-- <p-col :span="8">
            <p-form-item label="SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input v-decorator="['sn']" placeholder="请扫描或者输入SN"></p-input>
            </p-form-item>
          </p-col>  wireCompDTOList-->

          <p-col :span="8">
            <p-form-item label="线号/组件编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!--<p-input v-decorator="['palletno']" placeholder="请输入线号/组件编号"></p-input>-->

              <p-select showSearch v-model="currentPalletno" placeholder="请选择线号/组件编号" @change="palletnoChange">
                <p-select-option
                        v-for="(item,index) in model.wireCompDTOList"
                        :key="index"
                        :value="item.wcCode"
                >{{item.wcCode}}</p-select-option>
              </p-select>
            </p-form-item>
          </p-col>
        </p-row>
      </p-form>

      <h4 class="title">质量判定 </h4>
      <div>
        <p-descriptions  bordered size="small">
          <p-descriptions-item :label="currentPalletno" >
            <p-tag v-if="inspectResult==1" color="green"><p-icon type="check-circle" />合格</p-tag>
            <p-tag v-else-if="inspectResult==2" color="red"><p-icon type="close-circle" />不合格</p-tag>
          </p-descriptions-item>

          <p-descriptions-item label="总进度" >
            <p-progress
                    :stroke-color="{
                      '0%': '#108ee9',
                      '100%': '#87d068',
                    }"
                    :percent="percent"
            />
          </p-descriptions-item>

          <p-descriptions-item label="查看详情列表" >
            <!--<p-popover placement="left">
              <template slot="content" style="width:300px">
               ntentContentContentContentContentContentContentContent
              </template>

              <p-button type="primary" shape="round" icon="eye" />
            </p-popover>-->
            <p-button v-if="!showPTList" type="primary" icon="down"  @click="showPTBtn">查看</p-button>
            <p-button v-else type="primary" icon="up" @click="showPTBtn">收起</p-button>
          </p-descriptions-item>

        </p-descriptions>
      </div>

      <div style="margin-top: 30px" v-if="showPTList">
        <p-collapse defaultActiveKey="1" >
          <p-collapse-panel key="1" header="合格">
            <p-tag color="green" v-for="(item,index) in yesList" :key="index">
              {{item}}
            </p-tag>
          </p-collapse-panel>
          <p-collapse-panel key="2" header="不合格">
            <p-tag color="red" v-for="(item,index) in noList" :key="index" >
              {{item}}
            </p-tag>
          </p-collapse-panel>

        </p-collapse>
      </div>



      <h4 class="title">检验项目</h4>

      <!-- 表格 -->
      <p-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="tableScroll"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"

      >
        <!-- 实测值 -->
        <template slot="measuredValue" slot-scope="text,record" >
          <p-input
                  style="width:120px"
                  type="number"
            v-if="record.valueType==1"
            v-model="record.measuredValue"
                  @change="measuredValueInputChange(record.key)"
          />

          <p-select v-else v-model="record.measuredValue" @change="measuredValueChange(record.key)" style="width:100px">
            <p-select-option value="PASS">PASS</p-select-option>
            <p-select-option value="NG">NG</p-select-option>
          </p-select>
        </template>

        <div
          slot="filterDropdown"
          slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
          style="padding: 8px"
        >
          <p-input
            v-ant-ref="c => (searchInput = c)"
            :placeholder="`请输入 ${column.title}`"
            :value="selectedKeys[0]"
            style="width: 188px; margin-bottom: 8px; display: block;"
            @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])"
          />
          <p-button
            type="primary"
            icon="search"
            size="small"
            style="width: 90px; margin-right: 8px"
            @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
          >确认</p-button>
          <p-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">取消</p-button>
        </div>
        <div
          slot="filterDropdownDate"
          slot-scope="{ selectedKeys, confirm, clearFilters, column }"
          style="padding: 8px"
        >
          <p-form-item :label="` ${column.title}`">
            <j-date
              :show-time="true"
              date-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择开始时间"
              class="query-group-cust"
              v-model="queryParam[`${column.dataIndex}_begin`]"
            ></j-date>
            <span class="query-group-split-cust"></span>
            <j-date
              :show-time="true"
              date-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择结束时间"
              class="query-group-cust"
              v-model="queryParam[`${column.dataIndex}_end`]"
            ></j-date>
          </p-form-item>
          <p-button
            type="primary"
            icon="search"
            size="small"
            style="width: 90px; margin-right: 8px"
            @click="() => handleSearchDate(selectedKeys, confirm, column.dataIndex)"
          >确认</p-button>
          <p-button
            size="small"
            style="width: 90px"
            @click="() => handleResetDate(clearFilters,`${column.dataIndex}_begin`,`${column.dataIndex}_end`)"
          >取消</p-button>
        </div>
        <p-icon
          slot="filterIcon"
          slot-scope="filtered"
          type="search"
          :style="{ color: filtered ? '#108ee9' : undefined }"
        />

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt="图片不存在"
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <p-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)"
          >下载</p-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <p-divider type="vertical" />
          <p-dropdown>
            <a class="ant-dropdown-link">
              更多
              <p-icon type="down" />
            </a>
            <p-menu slot="overlay">
              <p-menu-item>
                <p-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </p-popconfirm>
              </p-menu-item>
              <template v-if="cgButtonLinkList && cgButtonLinkList.length">
                0
                v-for="(btnItem,btnIndex) in cgButtonLinkList">
                <p-menu-item :key=" 'cgbtnLink'+btnIndex " v-if="showLinkButton(btnItem,record)">
                  <a
                    href="javascript:void(0);"
                    @click="cgButtonLinkHandler(record,btnItem.buttonCode,btnItem.optType)"
                  >
                    <p-icon v-if="btnItem.buttonIcon" :type="btnItem.buttonIcon" />
                    {{ btnItem.buttonName }}
                  </a>
                </p-menu-item>
              </template>
            </p-menu>
          </p-dropdown>
        </span>
      </p-table>
    </div>

    <h4 class="title">审批记录</h4>
    <div>
      <p-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="approvalColumns"
              :dataSource="approvalList"
      >

      </p-table>
    </div>

    <mesQcInspectTaskChild-modal
      ref="modalForm"
      :EnhanceJS="EnhanceJS"
      @ok="modalFormOk"
      :mainId="mainId"
      :listaip="this.url.list"
    ></mesQcInspectTaskChild-modal>
  </p-card>
</template>

<script>
/*导入数字字典*/
import {
  initDictOptions,
  filterMultiDictText,
} from "@/components/dict/JDictSelectUtil";
import { axios } from "@/utils/request";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import MesQcInspectTaskChildModal from "./modules/MesQcInspectTaskChildModal";
import ButtonExpHandler from "@/components/jeecgbiz/modules/ButtonExpHandler";
import {
  postAction,
  getAction,
  deleteAction,
  httpAction,
  putAction,
  api,
} from "@/api/manage";

//弹窗复制过来的包
import { SubmitOnchangMixin } from "@/mixins/SubmitOnchangMixin";
import {} from "@/api/manage";
import pick from "lodash.pick";
import JDate from "@/components/jeecg/JDate";
import JSelectUserByDep from "@/components/jeecgbiz/JSelectUserByDep";
import JDictSelectTag from "@/components/dict/JDictSelectTag";



export default {
  name: "MesQcInspectTaskChildList2",
  mixins: [JeecgListMixin],
  components: { MesQcInspectTaskChildModal },
  props:['mqVisible','mqLoad','mqData'],
  /*watch: {
    mainId: {
      immediate: true,
      handler(val) {
        if (!this.mainId) {
          this.clearList();
        } else {
          this.queryParam["mesInspectTaskId"] = val;
          this.loadData(1);
        }
      },
    },
  },*/
  data() {
    return {
      form: this.$form.createForm(this),
      inspectResult: '', // 质量判定的 检验结果
      dataSource: [],
      //弹窗复制过来的数据
      title: "操作",
      width: 800,
      visible: false,
      model: { inspectBillno: "1" }, //对表单输入框的数据进行赋值的对象;
      currentPalletno:'',
      firstModal:{},
      approvalList:[],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,

      showPTList:false,

      yesList:[],
      noList:[],

      methodList:[],
      methodMap:[],
      standardUnitList:[],
      standardUnitMap:[],

      percent:0,

      inspectBillno: "",
      productionBillno: "",
      processBillno: "",
      rules: "",
      mcode: "",
      mname: "",
      operationDt: "",
      confirmTime: "",
      confirmBy: "",
      sn: "",
      palletno: "",

      url: {
        //数据库接口
        add: "/mes-quality/mesQcInspectTask/add",
        edit: "/mes-quality/mesQcInspectTask/edit",

        list: "/mes-quality/mesQcInspectTask/listMesQcInspectTaskChildByMainId",
        delete: "/mes-quality/mesQcInspectTask/deleteMesQcInspectTaskChild", //表格组件获得后台API的数据
        deleteBatch:
          "/mes-quality/mesQcInspectTask/deleteBatchMesQcInspectTaskChild",
        getColumns: "/mes-quality/online/cgform/api/getColumns/",
        buttonAction: "/mes-quality/online/cgform/api/doButton",
      },
      //end

      loading1:false,

      description: "首检操作(操作员)页面",
      disableMixinCreated: true,
      EnhanceJS: "",
      cgButtonLinkList: [],
      cgButtonList: [],
      code: "",
      dictOptions: {
        inspectStatus: [],
        inspectResult: [],
        valueType: [],
        individualJudgment: [],
      },

      approvalColumns:[
        {
          title: "序号",
          dataIndex: "",
          key: "rowIndex",
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          title: "时间",
          dataIndex: "createTime",
          customRender: (text) => {

            return this.formatDate(text+'',"YYYY-MM-DD HH:mm:ss");
          },
        },
        {
          title: "操作人员",
          dataIndex: "opeBy",
        },
        {
          title: "操作内容",
          dataIndex: "remark",
        },
        {
          title: "检验不合格工站",
          dataIndex: "inspectFailName",
          customRender: (text) => {
            if(!text){
              return '';
            }
            return text.replaceAll(',','，');
          },
        },
        {
          title: "状态",
          dataIndex: "opeContent",
        },
      ],
      // 表头
      columns: [
        {
          title: "序号",
          dataIndex: "",
          key: "rowIndex",
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          title: "工站",
          align: "center",
          dataIndex: "workStation",
        },
        {
          title: "检验项目",
          align: "center",
          dataIndex: "inspectProject",
        },
        {
          title: "检验标准",
          align: "center",
          dataIndex: "inspectStandard",
        },
        {
          title: "值类型",
          align: "center",
          dataIndex: "valueType",
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return text==1?'计量型':'计数型';
            }
          },
        },
        {
          title: "检验手段",
          align: "center",
          dataIndex: "inspectMethod",
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return this.methodMap[text].title;
            }
          },
        },
        {
          title: "参数",
          align: "center",
          dataIndex: "paramValue",
        },
        {
          title: "单位",
          align: "center",
          dataIndex: "standardUnit",
          customRender: (text) => {
            return this.standardUnitMap[text]?this.standardUnitMap[text].title:'';

          },
        },
        {
          title: "标准值",
          align: "center",
          dataIndex: "standardValue",
        },
        {
          title: "上限值",
          align: "center",
          dataIndex: "upperValue",
        },
        {
          title: "下限值",
          align: "center",
          dataIndex: "downValue",
        },

        {
          title: "实测值",
          align: "center",
          dataIndex: "measuredValue",
          scopedSlots: { customRender: "measuredValue" },
        },
        {
          title: "单项判定",
          align: "center",
          dataIndex: "individualJudgment",
          customRender: (text) => {
            if (!text) {
              return "";
            } else {
              return  text==1?'PASS':'NG';
            }
          },
        },
        {
          title: "检验人",
          align: "center",
          dataIndex: "judge",
        },

      ],
    };
  },

  computed: {
    /*tableScroll: function () {
      if (this.columns.length > 12) {
        return { x: this.columns.length * 160 + 40 };
      }
    },*/
  },

  created() {
    this.getMethodList();
    this.mqListener();
    this.setdefColumns();
    this.initButtonList();
  },
  mounted() {
    console.log("query", this.$route.query);
    console.log(this.model);

  },
  /*watch: {
    $route: function (new_value, old_value) {
      // console.log("路由新值", new_value);
      // console.log("路由旧值", old_value);

      // this.$emit("update: props参数名", 新参数值);
      getAction(`/mes-quality/mesQcInspectTask/selectById`, this.$route.query)
        .then((response) => {
          this.model = response.data;
          this.edit(this.model); //设置表单的值
          this.dataSource = response.data.mesQcInspectTaskChildList;
          console.log("接口返回数据成功", response);
          console.log(response.data);
        })
        .catch((response) => {
          console.log("接口无返回数据", response);
        });
    },
  },*/
  updated() {

  },
  methods: {
    mqListener(){
      console.log(this.mqVisible)
      console.log(this.mqLoad)
      console.log(this.mqData)
      this.initData(this.mqData.id)
    },
    backToIndex(){
      let mqData = this.mqData;
      this.$emit('update:mqVisible', 1);
      this.$emit('update:mqLoad', false);
      mqData.id = 0;
      mqData.isPallet = "";
      mqData.inspectStatus = "";
      this.$emit('update:mqData', mqData);
    },
    getMethodList(){
      getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_inspect_method'}).then(res=>{
        if(res.success){
          this.methodList = res.data;
          this.methodMap = this.listToMap(this.methodList,'value');
        }
      })
    },
    initStandardUnitList(){
      getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_details_tamplate_unit'}).then(res=>{
        if(res.success){
          this.standardUnitList = res.data;
          this.standardUnitMap = this.listToMap(this.standardUnitList,'value');
        }
      })
    },
    //封装listToMap
    listToMap(list,name){
      let map = {};
      for(let i in list){
        map[list[i][name]] = list[i];
      }
      return map;
    },

    showPTBtn(){
      this.showPTList=this.showPTList?false:true;
    },
    palletnoChange(){
      this.loading1 = true;
      let wcCode= this.currentPalletno;
      let id = this.mqData.id;


      postAction('/mes-quality/mesQcInspectTask/selectByLineNo',{id:id,wcCode:wcCode}).then(res=>{
        if(res.success){
          this.dataSource = res.data;
          let key = 1;
          this.dataSource.forEach(item=>{
            item.key =key;
            key = key+1;
            item.palletno=this.currentPalletno;
          })


          this.checkDetailDataToBasic();

        }else{
          this.$message.warning(res.msg);
        }
      }).then(res=>{
        this.loading1 = false;
      })
    },

    initData(id){
      // 获得表单和表格的数据


      getAction(`/mes-quality/mesQcInspectTask/selectById`, {id:id}).then(res=>{
        if(res.success){
          if(res.code!=0){
            this.$message.warning(res.msg)
          }
          let data  = res.data;
          this.model = res.data;
          this.firstModal = res.data;
          this.edit(this.model); //设置表单的值
          this.initYesNoList(this.model);

          this.approvalList = data.mesQcApproveRecordList;
          if(this.currentPalletno!=''){
            this.palletnoChange();
          }else{
            if(data.wireCompDTOList.length>0){
              this.currentPalletno= data.wireCompDTOList[0].wcCode;
              this.palletnoChange();
            }
          }
        }else{
          this.$message.warning(res.msg)
        }
      })

    },

    initYesNoList(data){
      let percent =0;
      let allSize = data.wireCompDTOList.length;
      let currentSize = data.qualifiedPallet.length;
      if(allSize>0){
        if(currentSize>0){
          percent = currentSize / allSize * 100;
        }
      }

     percent = parseFloat(percent.toFixed(2))

      this.percent = percent;
      this.yesList = data.qualifiedPallet;



      let noList = [];
      data.wireCompDTOList.forEach(item=>{
        let flag  = true;
        data.qualifiedPallet.forEach(j=>{
          if(item.wcCode==j){
            flag  = false;
          }
        })
        if(flag){
          noList.push(item.wcCode)
        }

      })

      this.noList = noList;





    },

    edit(record) {
      this.form.resetFields();
      this.model = Object.assign({}, record);
      this.model.inspectBy = this.$store.state.user.name;
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(
          //设置表单的值
          pick(
            this.model,
            "inspectBillno",
            "productionBillno",
            "processBillno",
            "mcode",
            "mname",
            "processTwo",
            "linename",
            "deviceCode",
            "inspectTimes",
            "inspectBy",
            "sendInspectTime",
            "palletno",
            "sn"
          )
        );
      });
    },
    //end

    //提交表单的数据
    submit_button() {
      console.log(123)
      let data = this.model;
      data.inspectResult = this.inspectResult;
      data.mesQcInspectTaskChildList = this.dataSource;

      data.mesQcInspectTaskChildList.forEach(item=>{
        item.mesInspectTaskId = data.id;
      })

      putAction('/mes-quality/mesQcInspectTask/updateMesQcInspectTask',data).then(res=>{
        if(res.success){
          this.$message.success("提交成功");
          this.backToIndex();
        }else{
          this.$message.warning(res.msg);
          this.initData(this.mqData.id)
        }
      })

    },

    saveData(){
      let data = this.model;
      data.mesQcInspectTaskChildList = this.dataSource;


      putAction('/mes-quality/mesQcInspectTask/save',data).then(res=>{
        if(res.success){
          this.$message.success("保存成功!");
          this.initData(this.mqData.id)

        }else{
          this.$message.warning(res.msg);
          this.initData(this.mqData.id)
        }
      })
    },

    /**
     *值类型为计数型 实测值为下拉选项框PASS值为1和NG值为2 值变动触发的提交动作
     */
    measuredValueChange(key) {
      this.dataSource[key-1].judge = this.$store.state.user.name

      /*this.resetYesOrNoList();*/
      this.checkDetailDataToBasic();

    },

    measuredValueInputChange(key){
      this.dataSource[key-1].judge = this.$store.state.user.name

      /*this.resetYesOrNoList();*/
      this.checkDetailDataToBasic();

      },

    resetYesOrNoList(){

      let oldInspectResult = this.inspectResult;
      let xbNum = this.model.palletno;

      let yesList = this.yesList;
      let noList = this.noList;
      this.checkDetailDataToBasic();
      if(oldInspectResult!=this.inspectResult){
        if(this.inspectResult==1){
          let index = noList.indexOf(xbNum);
          if (index > -1) {
            noList.splice(index, 1);
          }
          yesList.push(xbNum);
        }else{
          let index = yesList.indexOf(xbNum);
          if (index > -1) {
            yesList.splice(index, 1);
          }
          noList.push(xbNum);
        }
      }


      this.yesList = Object.assign([], yesList);
      this.noList = Object.assign([], noList);

      let percent = 0;
      let allSize = this.yesList.length+this.noList.length;
      let currentSize = this.yesList.length;
      if(allSize>0){
        if(currentSize>0){
          percent = currentSize / allSize * 100;
        }
      }
      this.percent = percent;
    },


    checkDetailDataToBasic(){
      let flag = true;
      this.dataSource.forEach(item=>{
        if(item.measuredValue||item.measuredValue!=""){

          if(item.valueType==2){
            if(item.measuredValue=='PASS'){
              item.individualJudgment =1
            }else{
              item.individualJudgment =2
              flag = false;
            }
          }else{

            let downValue = 0;
            let upperValue = 0;

            let measuredValue = parseFloat(item.measuredValue);

            if((item.downValue&&item.downValue!='')&&(item.upperValue&&item.upperValue!='')){
              downValue = parseFloat(item.downValue);
              upperValue = parseFloat(item.upperValue);
              if(measuredValue>=downValue&&measuredValue<=upperValue){
                item.individualJudgment =1
              }else{
                item.individualJudgment =2
                flag = false;
              }
            }else if((!item.downValue||item.downValue=='')&&(item.upperValue&&item.upperValue!='')){
              upperValue = parseFloat(item.upperValue);
              if(measuredValue<=upperValue){
                item.individualJudgment =1
              }else{
                item.individualJudgment =2
                flag = false;
              }
            }else if((item.downValue&&item.downValue!='')&&(item.upperValue||item.upperValue!='')){
              if(measuredValue>=downValue){
                item.individualJudgment =1
              }else{
                item.individualJudgment =2
                flag = false;
              }
            }else{
              if(measuredValue>=downValue&&measuredValue<=upperValue){
                item.individualJudgment =1
              }else{
                item.individualJudgment =2
                flag = false;
              }
            }
          }
        }else{
          flag = false;
        }

      })


      if(this.dataSource.length>0){
        this.inspectResult = flag?1:2;
      }else{
        this.inspectResult = 2;
      }







    },

    /**  加载时自动触发判断表格里所有单项判定是否PASS,全部PASS则判定选项变成合格,否则不合格 this.inspectResult的值控制检验结果
     * 单项判定 individualJudgment
     */
    pan_ding() {
      // let dataSource = this.dataSource;
      let pass = 0;
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].individualJudgment != "1") {
          pass = 0;
          console.log("质量判定不合格");
          return (this.inspectResult = 2);
        } else {
          pass = pass + 1;
        }
      }
      if (pass > 0) {
        console.log("质量判定合格");
        this.inspectResult = 1;
      }
    },

    setdefColumns() {
      if (this.columns.length > 12) {
        let arrLength = this.columns.length - 1;
        this.columns[0]["width"] = 70;
        this.columns[0]["fixed"] = "left";
      }
    },
    //确定按钮
    handleSearch(selectedKeys, confirm, dataIndex) {
      confirm();
      this.searchText = selectedKeys[0];
      this.searchedColumn = dataIndex;
    },
    //取消按钮
    handleReset(clearFilters) {
      clearFilters();
      this.searchText = "";
    },
    //确定时间
    handleSearchDate(selectedKeys, confirm, dataIndex) {
      confirm();
      this.searchText = selectedKeys[0];
      this.searchedColumn = dataIndex;
      this.searchQuery();
    },
    // 清除时间
    handleResetDate(clearFilters, begin, end) {
      if (this.queryParam[begin] || this.queryParam[end]) {
        this.queryParam[begin] = "";
        this.queryParam[end] = "";
        clearFilters();
        this.searchText = "";
        this.searchQuery();
      } else {
        clearFilters();
        this.searchText = "";
      }
    },
    getKey() {
      const dataItem = [];
      setTimeout(() => {
        this.columns.forEach((item) => {
          dataItem.push({ text: item.title, value: item.dataIndex });
        });
      }, 100);
      return dataItem;
    },
    getControl(dic) {
      const dataItem = [];
      initDictOptions(dic).then((res) => {
        res.data.forEach((item) => {
          dataItem.push({ text: item.text, value: item.value });
        });
      });
      return dataItem;
    },
    initDictConfig() {
      // 用值类型的值发送请求查询数据字典里的值类型的值对应的字符串
      initDictOptions("inspect_value_type").then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, "valueType", res.data);
        }
      });
      // 用检验结果的值发送请求查询数据字典里的检验结果的值对应的字符串
      initDictOptions("mes_individual_judgment").then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, "individualJudgment", res.data);
        }
      });
    },

    clearList() {
      // this.dataSource = [];
      this.selectedRowKeys = [];
      this.ipagination.current = 1;
    },
    showLinkButton(item, record) {
      let btn = new ButtonExpHandler(item.exp, record);
      return btn.show;
    },
    initButtonList() {
      getAction(`${this.url.getColumns}1f1fd813bd5446749f7f6f33bff10658`).then(
        (res) => {
          console.log("--获取自定义按钮->>", res);
          if (res.success) {
            this.code = res.data.code;
            this.initCgButtonList(res.data.cgButtonList);
            this.initCgEnhanceJs(res.data.enhanceJs);
          } else {
            this.$message.warning(res.msg);
          }
        }
      );
    },
    initCgEnhanceJs(enhanceJs) {

      if (enhanceJs) {
        let Obj = eval("(" + enhanceJs + ")");
        this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
        this.cgButtonJsHandler("created");
      } else {
        this.EnhanceJS = "";
      }
    },
    initCgButtonList(btnList) {
      let linkArr = [];
      let buttonArr = [];
      if (btnList && btnList.length > 0) {
        for (let i = 0; i < btnList.length; i++) {
          let temp = btnList[i];
          if (temp.buttonStyle == "button") {
            buttonArr.push(temp);
          } else if (temp.buttonStyle == "link") {
            linkArr.push(temp);
          }
        }
      }
      this.cgButtonLinkList = [...linkArr];
      this.cgButtonList = [...buttonArr];
      console.log("链接增强", this.cgButtonLinkList);
    },
    cgButtonJsHandler(buttonCode) {
      if (this.EnhanceJS[buttonCode]) {
        this.EnhanceJS[buttonCode](this);
      }
    },
    cgButtonActionHandler(buttonCode) {
      //处理自定义button的 需要配置该button自定义sql
      if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
        this.$message.warning("请先选中一条记录");
        return false;
      }
      if (this.selectedRowKeys.length > 1) {
        this.$message.warning("请只选中一条记录");
        return false;
      }
      let params = {
        formId: this.code,
        buttonCode: buttonCode,
        dataId: this.selectedRowKeys[0],
      };
      console.log("自定义按钮请求后台参数：", params);
      postAction(this.url.buttonAction, params).then((res) => {
        if (res.success) {
          this.loadData();
          this.$message.success("处理完成!");
        } else {
          this.$message.warning("处理失败!");
        }
      });
    },
    cgButtonLinkHandler(record, buttonCode, optType) {
      if (optType == "js") {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this, record);
        }
      } else if (optType == "action") {
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: record.id,
        };
        console.log("自定义按钮link请求后台参数：", params);
        postAction(this.url.buttonAction, params).then((res) => {
          if (res.success) {
            this.loadData();
            this.$message.success("处理完成!");
          } else {
            this.$message.warning("处理失败!");
          }
        });
      }
    },
  },
};
</script>

<style scoped>
@import url("~@assets/less/common.less");
.title {
  padding: 8px 12px;
  background: #fafafa;
}
.title:not(:first-child) {
  margin-top: 25px;
}
</style>